<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>

                    <el-col :md="6" :sm="12">
                        <el-form-item label="投放人员:"  prop="tf_admin.value" v-if="response == 1">
                            <SelectPage v-model="queryParams.tf_admin.value" :url="'/admin/system.admin/selectPage'" show_field="nickname" query_field="nickname" :multiple="false" />
                        </el-form-item>
                    </el-col>

                    <el-col :md="6" :sm="12">
                        <el-form-item label="编号:" prop="brand.value">
                            <el-input v-model="queryParams.brand.value" placeholder="请输入编号" clearable />
                        </el-form-item>
                    </el-col>

                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item label="投放状态:" prop="tf_status.value">
                            <el-select v-model="queryParams.tf_status.value" placeholder="请选择" clearable>
                                    <el-option label="请选择" :value="0" />
                                    <el-option label="无效" :value="0" />
                                    <el-option label="在投" :value="1" />
                                    <el-option label="已取消" :value="2" />
                                </el-select>
                        </el-form-item>
                    </el-col> -->

                    <el-col :md="6" :sm="12">
                        <el-form-item label="审核状态:" prop="apply_status.value">
                            <el-select v-model="queryParams.apply_status.value" placeholder="请选择" clearable>
                                    <el-option label="请选择" :value="0" />
                                    <el-option label="待审核" :value="0" />
                                    <el-option label="审核通过" :value="1" />
                                    <el-option label="审核不通过" :value="2" />
                                </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :md="12" :sm="12">
                        <el-form-item label="申请时间:" prop="add_time.value">
                            <el-date-picker
                                v-model="queryParams.add_time.value"
                                type="datetimerange"
                                range-separator="至"
                                start-placeholder="开始"
                                end-placeholder="结束"
                                align="right"
                                value-format="yyyy-MM-dd HH:mm:ss"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>

                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>

            
            <!-- <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row> -->

     
            <!-- 列表 -->
            <el-tabs v-model="activeTab" @tab-click="handleStatus" type="border-card">
                <el-tab-pane v-for="(item, index) in status" :key="index" :label="item.label" :name="item.value.toString()">
                    <qa-table
                        :source="tableData"
                        :columns="columns"
                        :selection="true"
                        :loading="loading"
                        @sortChange="sortChange"
                        @statusChange="statusChange"
                        @selectionChange="selectionChange"
                        id="quickadmin"
                    >
                         <template v-slot:action>
                    <el-table-column label="操作" width="240" align="left">
                        <template slot-scope="scope">
                            <el-button class="btn-mar" size="mini" type="primary" icon="el-icon-edit" @click="handleEdit(scope.row)"  v-if="scope.row.apply_status =='待审核'" v-hasPermi="api.edit">审核</el-button>
                            <el-button class="btn-mar" size="mini" type="primary" @click="cancel_tf(scope.row)" v-if="scope.row.tf_status !='已取消'" v-hasPermi="api.cancel_tf">取消投放</el-button>
                            <!-- <el-button class="btn-mar" size="mini" type="info" icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button> -->
                            <!-- <el-button class="btn-mar" size="mini" type="danger" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button> -->
                        </template>
                    </el-table-column>
                </template>
                    </qa-table>
                </el-tab-pane>
            </el-tabs>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen"  :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData"  :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>

    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    
    data() {
        return {
            // table结构
            response:0,
            columns: [
                {
                    visible: true,
                    label: '编号',
                    prop: 'brand',
                },
                {
                    visible: true,
                    label: '投放人员',
                    prop: 'tf_admin',
                },
                {
                    visible: true,
                    label: '投放状态',
                    prop: 'tf_status',
                },
                {
                    visible: true,
                    label: '审核状态',
                    prop: 'apply_status',
                },
                {
                    visible: true,
                    label: '申请时间',
                    prop: 'add_time',
                },
                {
                    visible: true,
                    label: '审核时间',
                    prop: 'check_time',
                },
                {
                    visible: true,
                    label: '备注',
                    prop: 'content',
                },

            ],
            // 接口地址
            api: {
                index: `/admin/tfrecord/index`,
                find: `/admin/tfrecord/find`,
                add: `/admin/tfrecord/add`,
                edit: `/admin/tfrecord/edit`,
                delete: `/admin/tfrecord/delete`,
                export: `/admin/tfrecord/export`,
                status: `/admin/tfrecord/status`,
                cancel_tf: `/admin/tfrecord/cancel_tf`,
            },
            editFormParams: {
            },
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
              //是否展示搜索
            showSearch: true,
            // 查询参数
            queryParams: {
                brand: { value: undefined, op: '%like%' },
                tf_status: { value: undefined, op: '%like%' },
                tf_admin: { value: undefined, op: '%like%'},
                apply_status: { value: undefined, op: '%like%'},
                // add_time: { value: undefined, op: '%like%'},
                add_time: { value: [], op: 'range' },
             },

            status: [
                { label: '全部', value: 0 },
                { label: '在投', value: 2 },
                { label: '已取消', value: 3 },
                { label: '无效', value: 1 },
             ],
             activeTab: '',

        }
    },
    created () {
        this.initIndex()
        this.handleSkuFind()
    },
    watch: {
        
    },
    methods: {
        // 案列：当前组件格式化方法
        testFormatter(prop) {
            return prop
        },
         // 订单状态切换查询
        handleStatus(tab) {
            if(tab.name == 0){
                this.queryParams.tf_status.value = null
            }else{
                this.queryParams.tf_status.value = tab.name-1
            }
            this.submitSearch()
        },

        cancel_tf(row) {
            this.$confirm(`是否确认取消投放?`, '警告', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                })
                .then(() => {
                    this.request.post(this.api.cancel_tf, { 
                        id: row.id,
                    })
                    this.$message.success('取消成功');
                    this.initIndex();
                })
                .then(() => {
                })
                .catch(() => {})
                .finally(() => {
                    
                })
        },
        async handleSkuFind() {
            let response = await this.request.post('/admin/index/judgment_authority', { 
                
            })
            this.response = response;
            
        }
    }
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
</style>
